<?
	include("common.php");

	include("header.php");
	$qr1 = mysql_query("SELECT * FROM forum WHERE id=$forum AND uid='$myuid'");
	$i = "1";
	$forums = mysql_fetch_object($qr1);
	$bid = $forums->id;
?>
<p><font face=arial size=3>
<table border="0" cellpadding="10" cellspacing="0" width="85%" align="center">
<tr>
	<td align="left">
<?
	if($delt){
		$num = 1;
		$sql = "SELECT * FROM posts WHERE threadid=$delt";
		$qr1 = mysql_query($sql);
		while( $row = mysql_fetch_object($qr1) ){
			$tid = $row->id;
			$sql = "DELETE FROM posts WHERE id=$tid";
			$qr1 = mysql_query($sql) or die( mysql_error()."<br>$sql" );
			$num++;
		}
		$sql = "DELETE FROM thread WHERE id=$delt";
		$qr1 = mysql_query($sql) or die( mysql_error()."<br>$sql" );
	}else if($delp){
		$sql = "DELETE FROM posts WHERE id=$delp";
		$qr1 = mysql_query($sql) or die( mysql_error()."<br>$sql" );
	}
?>
<TABLE class=design bgColor=#ffffff cellPadding=3 cellSpacing=0 width=100% border='1' BORDERCOLOR="#C0C0C0" STYLE="border-collapse: collapse">
<TR>
	<TD class='a1'><strong>title</font></strong></td>
	<TD class='a1'><strong>body</font></strong></td>
	<TD class='a1'><strong>posted by</font></strong></td>
	<TD class='a1'><strong>action</font></strong></td>
</tr>
<?
	$sql = "SELECT * FROM thread WHERE mb=$bid";
	$result = mysql_query($sql) or die( mysql_error() );
	if ($result){
		while( $row = mysql_fetch_object($result) ){
			list($username) = mysql_fetch_row( mysql_query("SELECT username FROM users WHERE uid='".$row->uid."'") );
			$row->username = $username;
?>
			<tr>
				<TD class='a1'>
					<?=$row->title?></font>
				</td>
				<TD class='a1'>
					<?=$row->body?></font>
				</td>
				<TD class='a1'>
					<a href="viewprofile.php?uid=<?=$row->uid?>"><?=$row->username?></a></font>
				</td>
				<TD class='a1'>
						<a onclick="return confirm('are you sure you wish to delete this thread?');" href="manageforum.php?forum=<?=$bid?>&&step=6&delt=<?=$row->id?>"><font color=black>remove</a>
					</font>
				</td>
			</tr>
<?
			$tid = $row->id;
			$asql = "SELECT * FROM posts WHERE threadid=$tid";
			$aresult = mysql_query($asql) or die( mysql_error() );
			if ($aresult){
				while( $arow = mysql_fetch_object($aresult) ){
					list($username) = mysql_fetch_row( mysql_query("SELECT username FROM users WHERE uid='".$arow->uid."'") );
					$arow->username = $username;
?>
					<tr>
						<TD class='a1' style="padding-left:10px">
							<?=$arow->title?></font>
						</td>
						<TD class='a1'>
							<?=$arow->body?></font>
						</td>
						<TD class='a1'>
							<a href="users.php?a=e&step=2&uid=<?=$arow->uid?>"><?=$arow->username?></a></font>
						</td>
						<TD class='a1'>
								<a onclick="return confirm('are you sure you wish to delete this post?');" href="manageforum.php?forum=<?=$bid?>&&step=6&delp=<?=$arow->id?>"><font color=black>remove</a>
							</font>
						</td>
					</tr>
<?
				}
			}
		}
	}
?>
</table>
	</td>
</tr>
</table>
</font></p>
<?
	include("footer.php");
?>